mma2ltx

Version 1.2

Giuseppe Ghibò ⟨ghibo@galileo.polito.it⟩

July 19, 1994

Mma2ltx is a program which allows to a Mathematica user to include the graphics produced by Mathematica in a LaTEX document using own LaTEX fonts and symbols.

1 Introduction

Mathematica has perhaps the best data plotting tool currently available, but its control over mathematical symbols and formulæ inside graphics is very poor^{1}: it is limited to the characters available in the font ‘Symbol’.

TEX instead is very powerful in this subject but has no data plotting capability: it can only include external graphics.

mma2ltx is the “bridge” across the two worlds: it allows to use any LaTEX symbol and font as labels in graphics created by Mathematica.

2 What does mma2ltx do?

Mma2ltx reads a PostScript graphic file generated by the Mathematica command ‘Display’^{2} and writes two output files; the first one is a LaTEX file and contains every string of text of the original graphics file in LaTEX form; the latter is an EPSF file: it substantially contains the same things of the original PostScript file, except it has been stripped of any string of text.

3 Requirements

In order to include Mathematica graphics processed by mma2ltx into LaTEX documents you need LaTEX (obvious) and the Rokicki’s dvips^{3} dvi processor.

Files processed by mma2ltx were tested under LaTEX v2.09 (25 March 1992) and dvips v5.55 (27 March 1994). The graphics files used were created with Mathematica^{4} v2.2.

4 Distribution/Disclaimer

mma2ltx is shareware. If you find it useful (or continue using it longer than a week) please consider paying the fee of of Lit. 20.000 (Italian Lire), or US $15 (US Dollars), or 20 DM (German Marks), or 80 Fr. (French Francs), or £10 (British Pounds) to the author (see §13 for the author’s address).

This software is provided ”as is” with no explicit or implicit guarantee of any kind. The author is not responsible for any misuse, or damages caused by mma2ltx. You are using it at your own risks.

mma2ltx is Copyright \begin{matrix}c \\ ◯ \end{matrix} 1994 by Giuseppe Ghibò.

The program may be freely distributed and copied as long as the following conditions are acknowledged:

1Mathematica supports output in TEX form, but this feature is only for formulæ and doesn’t regard the graphics.

2The ‘Display’ command saves a raw PostScript representetion of a graphic in a file.

3dvips is a converter from dvi to PostScript files. It was developed by T. Rokicki and is available via anonymous FTP from labrea.stanford.edu or in any CTAN site.

4Mathematica is Copyright \begin{matrix}c \\ ◯ \end{matrix}1988, 1994 by Wolfram Research, Inc.

• All parts of the program and the documentations must be left intact in any ways. The distribution of single parts is not allowed. The repacking of this distribution with other packers is, however, allowed.

5 Using mma2ltx

To use mma2ltx, just type

C:\> mma2ltx mypic.ps

where mypic.ps is the output of the Mathematica’s primitive ‘Display’. mma2ltx supports many options. They are described in the next section.

6 Command Line Options

Options are specified on the command line using a dash ‘-’ followed by a letter. No spaces are allowed between the ‘-’ and the letter. The letter may be followed by an argument. Spaces between the letter and the argument are allowed instead.

Here follows a description of the options supported by mma2ltx. Facultative arguments are indicated in the ‘Template’ enclosed between square brackets […].

Note that every string in the command line which is not an option argument is taken as an input file.

6.1 Option -?

Option -? (-"?" on Unix) shows the following help messages:

mma2ltx v1.2 - Copyright (C) 1994 Giuseppe Ghibo`
Usage: mma2ltx [<options>] <filename(s)> [<options>]
Where <options> is one or more of:
  -?  Show these messages
  -d  Don't keep the aspect ratio
  -n  Deactivate automatic $...$ enclosing
  -p  Include the Mathematica PostScript prologue in the .EPS file
  -b  Enclose every string into a white box (default = transpar. box)
  -h<dimen> Set picture height to <dimen> (default = 100bp)
  -w<dimen> Set picture width  to <dimen> (default = 161bp)
  -f<dimen> Add an \fbox to the picture (\fboxsep=<dimen>)
  -u<unit>  Set all dimensions in the unit <unit>
  -s<cmd>   Set the font size with the TeX command <cmd>
  -o<filename> Output filename
  -c(sx,sy)=(newsx,newsy)(<dimen>,<dimen>) (change alignment)
  <dimen> = a number followed by one of TeX's unit (e.g. 10.3cm)

  <unit>  = a TeX's unit (e.g. cm)
  <cmd>   = a TeX command without the backslash '\'
Example:
 mma2ltx -sfootnotesize -w5in pic1.ps pic2.ps
process the files `pic1.ps' and `pic2.ps'. The width of the pictures
will be 5 inch and \footnotesize will be used as LaTeX command to
set the pictures font size.

6.2 Options -w and -h

Template: -w⟨dimen⟩

-h⟨dimen⟩

Options -w and -h must be used to specify respectively the width and the height of the picture. The argument ⟨dimen⟩ is a number followed by one of TEX’s unit (i.e. one of mm, cm, pt, bp, pc, in, dd, cc, sp). For example, ‘-w10.3cm’ specifies a 10.3 cm wide picture. Note that ‘-w 10.3cm’, ‘-w=10.3cm’ and ‘-w:10.3cm’ are accepted too, but ‘-w10.3 cm’ isn’t accepted (note the space after the number 10). Note also that may be specified only one of ’-w’ or ’-h’: the other dimension is calculated to keep the Mathematica aspect ratio. If either the width and the height are specified, the picture will have (approximately) that dimensions, but the inside graphic will have dimension such to fit one of height or width, according to the aspect ratio. For instance, if we specify on the command line ‘-w10cm -h10cm’ and the aspect ratio^{5} is 0.62 then the picture will be 10 cm × 10 cm large (this is the dimension “visible” to LaTEX), but the inside graphic will be 10 cm wide and 6.2 cm high. If we have instead ‘-w10cm -h3cm’, the picture will be 10 cm × 3 cm large but the inside graphic will be just 4.84 cm wide and 3 cm high. If we don’t want to keep the Mathematica aspect ratio we must use the -d option. Default width is 161 bp; default height is 100 bp.

6.3 Option -d

Suppress the aspect ratio keeping.

6.4 Option -n

By default mma2ltx encloses every string grabbed from the Mathematica PostScript file into a $… $ pair. Specifying the -n option on the command line, this behaviour will be disabled.

6.5 Option -b

By default every string is disposed on the graphic as if it was enclosed in a transparent box. Using this option every string will be no longer “transparent”, but rather enclosed in a white box having the same size (see the string “some text” shown in Fig. 3 for the behaviour of this option).

5The aspect ratio is height/width in scaled coordinates (i.e., from 0 to 1).

6.6 Option -o

Template: -o⟨filename⟩ Specify the output filename. By default mma2ltx uses as output filenames the input filename stripped by the extension to which append the proper file extension (i.e., ‘.tex’ for the LaTEX file and ‘.eps’ for the EPSF file). The -o option allows you to specify a different name for the EPSF PostScript output file. In this case the name of the LaTEX file will be ⟨filename⟩.tex.

6.7 Option -f

Template: -f [⟨dimen⟩] The -f option tells mma2ltx to enclose the whole picture into an \fbox. The optional argument is the amount of \fboxsep; by default mma2ltx assumes \fboxsep=0pt. For instance the command

mma2ltx -f5pt -w8cm mypic.ps

produces a picture 8 cm wide, enclosed into \fbox; from the edges of the box and its contents there are 5 pt.

6.8 Option -s

Template: -s⟨control sequence⟩ This option specifies a LaTEX font-size control sequence to change the size of the picture labels. Note that mma2ltx doesn’t check if the ⟨control sequence⟩ is a valid LaTEX command. So be careful.

Generally a LaTEX font-size command may be one of tiny, scriptsize, footnotesize,

normalsize, large, Large, LARGE, huge, Huge or one of vpt, vipt viipt, viiipt, ixpt,

xpt, xipt, xiipt, xiv, xviipt, xxpt, xxvpt. No leading backslash is needed (you must use

-sfootnotesize instead of -s\footnotesize).

By default the picture uses the LaTEX current font size. Note that this command will affect size the of all the strings contained in the picture.

6.9 Option -u

Template: -u⟨TEX’s unit⟩ The -u option specifies the unit of measure of quantities contained in the .tex file generated by mma2ltx. Also the messages shown during LaTEX and mma2ltx processing will use that unit.

6.10 Option -p

By default the EPSF file produced by mma2ltx doesn’t contains the Mathematica PostScript prologue (i.e., it cannot be printed as is). In fact this prologue is included only once in the final PostScript file produced by dvips. Using this option the EPSF file produced by mma2ltx will contains the Mathematica prologue file. This may be very useful for some dvi previewer with capability to show PostScript specials.

6.11 Option -c

Template: -c⟨(s_{x}, s_{y}) = (s′_{x}, s′_{y})(dimen_{x}, dimen_{y})⟩

The -c option can be used to override a peculiar behaviour of Mathematica’s primitive Text. To place text, mma2ltx normally uses the same conventions of the Mathematica’s primitive ‘Text’: reference point (x, y) is realized as follows:

• The text string is placed into a box having the same size.

• An offset (s_{x}, s_{y}) in the bounding box coordinates system (see the Fig. 1) determines where the reference point goes.

For instance the offset (−1, 1) means that the box containing the string is placed with the point (−1, 1) at the reference point (x, y), i.e. left and top aligned.

If the offset is (0, 0) then the box is centered on the reference point (x, y).

[figure: Text \frac{1}{x}; (1, 1); (1, 0); (1, −1); (0, −1); (−1, −1); (−1, 0); (−1, 1); (0, 1); s_{x}; s_{y}]

Figure 1: Bounding box coordinates.

Note that we may also have offsets greater than

1. For instance the labelling of the x-axis is realized (by Mathematica) using a reference point lying on the x-axis and a bounding box offset of (0, 2). With this offset, different height x-labels would be placed at different distance from the x-axis. The ‘-c’ option bypasses this behaviour. It replaces any labels having (s_{x}, s_{y}) bb-offset with labels having (s′_{x}, s′_{y}) bb-offset further shifted by (dimen_{x}, dimen_{y}) from the current position (dimen_{x} and dimen_{y} must be numbers followed by one of TEX’s unit). The following example could make this clear. Consider a graphic having the following labels

−\frac{3}{2}  − 1  − \frac{1}{2}  \frac{1}{2}  1  \frac{3}{2}

under the x-axis. Since labels ‘−\frac{3}{2}’, ‘−\frac{1}{2}’, ‘\frac{1}{2}’ and and ‘\frac{3}{2}’ are higher than label ‘−1’ and ‘1’, they are placed lower than the labels ‘−1’. Using the option ‘-c(0,2)=(0,1)(0pt,-5pt)’ every labels will be placed with the top edge of the box that bounds them, at 5 pt from the x-axis, as shown in Fig. 2.

7 Including mma2ltx figures

To include a picture processed by mma2ltx into a LaTEX documents, first you should move the file ‘mmatext.sty’ in your LaTEX input directory and the files ‘texmma22.pro’, ‘mmawhite.eps’ in your TEX PostScript directory^{6}. Then include the style ‘mmatext’ at the top of your document:

6This is the directory where you keep the dvips prologue files.

−\frac{3}{2} −1 −\frac{1}{2}  \frac{1}{2}  1  \frac{3}{2} −1 −0.5 0.5 1  ^{−\frac{3}{2} −1 −\frac{1}{2}  \frac{1}{2}  1  \frac{3}{2} −1 −0.5 0.5 1}
Without ‘-c’ correction  With ‘-c’ correction

Figure 2: Behaviour of the ‘-c’ option.

\documentstyle[...,mmatext,...]{...}

and invoke the following macro at the point where you wish to include the picture:

\input{mypic}

where ‘mypic’ is the name of the file processed by mma2ltx. Note that the command ‘\input{mypic}’ may be invoked within any LaTEX environment, for instance the commands:

\begin{figure}
   \centering
   \tabcolsep=1cm
   \begin{tabular}{cc}
      \input{mypic1} &\input{mypic2} \\[2cm]
      \input{mypic3} &\input{mypic4}
   \end{tabular}
\end{figure}

will produce a figure containing four Mathematica pictures. Sometimes, during the LaTEX processing of a LaTEX file containing one or more mma2ltx pictures a message as

Mathematica picture: 'mypic.eps' deltax=0.48502 cm

or a message as

Mathematica picture: 'mypic.eps' deltay=1.28744 cm

or both, could appear. If this happens it means that the picture is wider or higher (by the amount shown) than the picture whose dimensions were established with mma2ltx.

8 Generating Mathematica pictures

mma2ltx needs a PostScript file. This file must be created from within Mathematica using the primitive ‘Display’ (see the Mathematica manual for a detailed description of this primitive).

Since mma2ltx just executes a plain translation of every string contained in the Mathematica PostScript file, we may specify a LaTEX control sequence directly from within Mathematica. For instance, to mark ticks with the LaTEX greek letter ‘π’, we may use

   Show[g, Ticks -> {{0, {Pi/2, "\\pi\\over2"}, {Pi, "\\pi"},
    {3Pi/2, "3{\\Pi\\over2}"}, {2Pi, "2\\pi"}, Automatic}]

Note, to obtain the backslash ‘\’ from within Mathematica it must be doubled. So every LaTEX control sequence specified into a Mathematica string must be preceded by a ‘\\’.

For example to place the formula

f(x) = sin \frac{1}{x}

at the point (0.5, 0.5) of a graphic, left and bottom aligned, we may use the Mathematica command

Text["f(x)=\\sin\\frac{1}{x}", {0.5,0.5}, {-1,-1}]

9 Manual adjustment of labels

Sometimes may happens to have two or more labels too much closed each other. In this case a manual adjustment is needed. To do this, edit the file generated by mma2ltx having the extension ‘.tex’. For instance, let’s analyze the file ‘mypic.tex’:

% Picture: mypic.eps
% Created by mma2ltx v1.2 - Copyright (C) 1994 Giuseppe Ghib\`o
% Command line : mma2ltx -ucm -w10cm -sfootnotesize mypic.ps
% Creation date: Sat Jul 16 10:40:43 1994
\mmaheaderprotrue
{%
\footnotesize%
\mmasetpic(10.0000,6.1803)[cm]{mypic.eps}
\mmatextfits(2.152,3.090)(0,2){$0.2$}
\mmatextfits(4.051,3.090)(0,2){$0.4$}
\mmatextfits(5.949,3.090)(0,2){$0.6$}
\mmatextfits(7.848,3.090)(0,2){$0.8$}
\mmatextfits(9.747,3.090)(0,2){$1$}
\mmatextfits(0.129,0.157)(1,0){$-1$}
\mmatextfits(0.129,1.623)(1,0){$-0.5$}
\mmatextfits(0.129,4.557)(1,0){$0.5$}
\mmatextfits(0.129,6.024)(1,0){$1$}
\mmatextfits(5.000,4.557)(-1,-1){$f(x)= \sin \frac{1}{x}$}
\begin{mmapicture}
\mmaputtext(2.152,3.090)(0,2){$0.2$}
\mmaputtext(4.051,3.090)(0,2){$0.4$}

\mmaputtext(5.949,3.090)(0,2){$0.6$}
\mmaputtext(7.848,3.090)(0,2){$0.8$}
\mmaputtext(9.747,3.090)(0,2){$1$}
\mmaputtext(0.129,0.157)(1,0){$-1$}
\mmaputtext(0.129,1.623)(1,0){$-0.5$}
\mmaputtext(0.129,4.557)(1,0){$0.5$}
\mmaputtext(0.129,6.024)(1,0){$1$}
\mmaputtext(5.000,4.557)(-1,-1){$f(x)= \sin \frac{1}{x}$}
\end{mmapicture}%
}%

We may observe that every label appears twice in the .tex file: within the command \mmatextfits and in the command \mmaputtext (and sometimes in the command \mmaputtext*). These commands have the following syntax:

                 \mmatextfits(x, y)(s_{x}, s_{y})[(off_{x}, off_{y})]{object}
                 \mmaputtext (x, y)(s_{x}, s_{y})[(off_{x}, off_{y})]{object}
                 \mmaputtext*(x, y)(s_{x}, s_{y})[(off_{x}, off_{y})]{object}

where (x, y) are the coordinates of the reference point. (s_{x}, s_{y}) are the bounding box coordinates as explained at §6.11. (off_{x}, off_{y}) is an optional argument and represents the offset in the x and y direction from the reference point (x, y). {object} may be any LaTEX object (even another mma2ltx picture). The unit of measure is the one which appears in \mmasetpic command (in this case cm). The command ‘\mmaputtext*’ has the same effect of \mmaputtext, except it encloses the object in a white box (see the text “some text” in the 3D graphic shown in Fig. 3).

For instance suppose we want to move right the label ‘0.2’ by 0.5 cm, then we must replace the line

\mmatextfits(2.152,3.090)(0,2){$0.2$}

with the line

\mmatextfits(2.152,3.090)(0,2)(0.5,0){$0.2$}

and the line

\mmaputtext(2.152,3.090)(0,2){$0.2$}

with the line

\mmaputtext(2.152,3.090)(0,2)(0.5,0){$0.2$}

Note that this approach is similar to the one explained at §6.11, with the exception that we may control every label, rather than a group of labels.

Now suppose we want to replace the label ‘0.8’ placed under the x-axis with the label ‘x_{1}’ to place over the x-axis with the low edge of the (invisible) box that bounds this label at 0.2 cm from the x-axis. In this case we must replace the lines

\mmatextfits(7.848,3.090)(0,2){$0.8$}
.
.
.
\mmaputtext(7.848,3.090)(0,2){$0.8$}

with the lines

\mmatextfits(7.848,3.090)(0,-1)(0,0.2){$x_1$}
.
.
.
\mmaputtext(7.848,3.090)(0,-1)(0,0.2){$x_1$}

The result is shown in Fig. 3.

0.2  0.4  0.6  x_{1}  1 −1 −0.5 0.5 1  f(x) = sin \frac{1}{x}^{^{−2}  ^{0}  ^{2}  ^{−2}^{0} ^{2}^{−1}^{−0.5}^{0}^{0.5}^{1} ^{−2}  ^{0}  ^{2} some text}

Figure 3: A sample figure.

10 Distribution Files

This archive contains the following files:

msdos/mma2ltx.exe Binary executable for MS/DOS
amiga/mma2ltx  Binary executable for the Amiga

mma2ltx.c  C source

mmatext.sty  LaTEX macros file
texmma22.lpro  Mathematica v2.2 PostScript prologue file

texmma22.pro  Squeezed version of ‘texmma22.lpro’

mmawhite.eps  A PostScript file needed to ‘mmatext.sty’
Makefile  A Unix Makefile
makefile.ami  Makefile for the Amiga
doc/mma2ltx.dvi  Documentation of mma2ltx (dvi form)
doc/mma2ltx.ps  Documentation of mma2ltx (PostScript form at 300 dpi)
doc/mma2ltx6.ps  Documentation of mma2ltx (PostScript form at 600 dpi)
doc/6mag.eps  mma2ltx EPSF file (needed to ‘mma2ltx.dvi’)
doc/12mag.eps  mma2ltx EPSF file (needed to ‘mma2ltx.dvi’)

doc/12mag 3d.eps mma2ltx EPSF file (needed to ‘mma2ltx.dvi’)

doc/optc.eps  mma2ltx EPSF file (needed to ‘mma2ltx.dvi’)

mysample.tex  A sample file

mypic.ps  A sample picture created by Mathematica
mypic.tex  The file ‘mypic.ps’ as processed by mma2ltx
mypic.eps  The file ‘mypic.ps’ as processed by mma2ltx
README  A short description of mma2ltx.

11 Limits of mma2ltx

Currently aren’t (yet) supported:

• rotated labels.

• multiple graphics (the ones produced with GraphicsArray).

• the ‘...->FontForm’ Mathematica parameter.

12 To do list

Here follow future enhancements which are on my list: • Add support for LaTEX 2ε.

• Add support for rotated labels.

• Add support for others dvi to PostScript processors.

13 Author info

If you have some questions, suggestions, comments, bug report or enhancement requests, please feel free to contact me at one of the following addresses:

• snail mail:

Ghibò Giuseppe via Sestriere, 133 10090 Cascine Vica – Rivoli (Torino) ITALY

• internet: ghibo@galileo.polito.it

14 Acknowledgements

The author wishes to thanks:

• P. Lepora for his significative suggestions and collaboration.

• P. Boieri for his suggestions and for having intensely tested mma2ltx.

15 History

version 1.2

• Added support to obtain non-transparent objects. Now objects (strings, pictures and so on), can be placed to overlap the background graphic, i.e. as if they were non-transparent.

• Added PostScript documentation for 600 dpi printers.

• Added binary executable for the Amiga.

version 1.1 First public release.